<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="程月">
    <title>倒计时</title>
    <style>
    .time{
        width: 300px;
        /* height: 80px; */
        margin: 0 auto;
        background-color: #333;
        color: white;
        text-align: center;
        padding: 5px;
        font-size: 24px;
    }
    input{
        display: inline-block;
        width: 50px;
        background-color: #fff;
        border: 2px  solid #888;
        padding: 0 10px;
        margin: 0 10px;
        color: #000;
        font-size: 24px;
    } 
    button{
        width: 160px;
        height: 30px;
        background-color: lightsteelblue;
        border: 0;
        font-size: 22px;
    }
    </style>
</head>
<body>
     <div class="time">
        <p><input class="sec" value="2">分
           <input class="min" value="0">秒</p>
        <button type="button">开始倒计时</button>
	</div>
</body>
</html>
<script>
    var sec = document.querySelector('.sec');
    var min = document.querySelector('.min');
    var button = document.querySelector('button');

    var second = Number(sec.value);
    var minute = Number(min.value);
    // console.log(second);
    // console.log(minute);
   

    function mint(){
        if (minute > 0 && minute < 60) {
            minute = minute - 1;
        } else if(minute==0){
            minute = 59;
            second = second - 1;
        }else{
            return;
        }
        min.value = minute;
        sec.value = second;
    }
     
     function s(){
         if (second == 0 && minute==0) {
            return;
        }
     }

    var timer = setInterval(mint,1000);
    var timer1 = setInterval(s,1000);

    var isclick = false;
    button.onclick= function (){
        if (isclick) {
            clearInterval(timer);
            clearInterval(s);
            button.innerHTML = '开始倒计时';
            isclick=false;
        } else {
            timer = setInterval(mint,1000);
            timer1 = setInterval(s,1000);
            button.innerHTML = '暂停倒计时';
            isclick=true;
        }
    }
</script>